package cn.tedu;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class Demo01 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入员工姓名");
        String name = sc.nextLine();
        System.out.println("请输入员工工资");
        int sal = sc.nextInt();
        //获取连接
        try (Connection conn = DBUtils.getConn()){
            //准备插入数据的SQL语句
            String sql = "insert into emp values(null,?,?)";
            //创建预编译的执行SQL语句的对象
            PreparedStatement ps = conn.prepareStatement(sql);
            //替换?的值
            ps.setString(1,name);
            ps.setInt(2,sal);
            ps.executeUpdate();
            System.out.println("添加完成!");

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
